// ---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "WebSupportThread.h"
#pragma package(smart_init)
// ---------------------------------------------------------------------------

__fastcall TWebSupportThread::TWebSupportThread(bool CreateSuspended) : TThread(CreateSuspended) {
	FreeOnTerminate = true;
}

// ---------------------------------------------------------------------------
void __fastcall TWebSupportThread::Execute() {
	if (Loading)
		Synchronize(&Load);
	try {
		String key = EncodeString(TGlobalVariable::UserInfo.UserKey);
		String name = EncodeString(ServiceParameter.ServiceName);
		String param = EncodeString(ServiceParameter.Serialize());
		Data = DecodeString(Form->WebService(key, name, param));
		Succeed = true;
	}
	catch(Exception & e) {
		Data = e.Message;
		Succeed = false;
	}
	if (Loading)
		Synchronize(&UnLoad);
	Synchronize(&CallBack);
}

// ---------------------------------------------------------------------------
void __fastcall TWebSupportThread::CallBack() {
	try{
		Form->DefaultCallBack(Succeed, Data, Tag);
	}catch(...){
	}
}

// ---------------------------------------------------------------------------
void __fastcall TWebSupportThread::Load() {
	Form->Load();
	WindowList = DisableTaskWindows(ULoadingForm->Handle);
}

// ---------------------------------------------------------------------------
void __fastcall TWebSupportThread::UnLoad() {
	EnableTaskWindows(WindowList);
	Form->UnLoad();
}
// ---------------------------------------------------------------------------
